package com.gaoyi.crm.repository;

import com.gaoyi.crm.db.dao.HttpCacheDao;
import com.gaoyi.crm.db.entity.HttpCache;
import com.gaoyi.crm.repository.base.BaseCacheRepository;

import java.util.List;

public class CacheRepository extends BaseCacheRepository<HttpCache, HttpCacheDao> {

    @Override
    protected HttpCacheDao getDao() {
        return mDatabase.getCacheDao();
    }

    public void insertCache(HttpCache... caches) {
        new Thread(() -> mDao.insert(caches)).start();
    }

    public String getCacheResponse(String url, String param) {
        List<HttpCache> list = mDao.getAllCache(url, param);
        if (list != null && !list.isEmpty()) {
            return list.get(list.size() - 1).getResponse();
        }
        return "";
    }
}
